/*
*	The Encounter Manager 'class' acts as a Mediator for the HTML Interface
* and the Actor objects of the program.
*
*	@Author nicholas.malacarne@gmail.com
*/
function EncManager(){
	
	// list of actors -nm
	var actorList = [];
	
	/*
	*	Sort Actor list by total value in descending order
	*
	*	@Author nicholas.malacarne@gmail.com
	*/
	var sort	= function(){
	
		actorList.sort( function( a, b ){ return b.getTotal() - a.getTotal(); } );
		
	} // end method
	
	/*
	*	Add an Actor object to the manager.
	*
	*	@Author nicholas.malacarne@gmail.com
	*
	*	@Param aActor An Actor object
	*/
	this.addActor = function( aActor ){ 
		
		// argument type check -nm
		if ( !( aActor instanceof Actor ) ){ throw "EncManager::addActor( Actor ) : invalid argument data!"; }
		
		// add new Actor object to Actor list -nm
		actorList.push( aActor );
		
		// sort list -nm
		sort();
		
	} // end method
	
	/*
	*	Remove a previously added Actor from the actor list
	*
	*	@Author nicholas.malacarne@gmail.com
	*
	*	@Param aId A string id of which Actor we wish to remove
	*/
	this.removeActor	= function( aId ){
		
		// argument type check -nm
		if ( typeof aId != "string" ){ throw "EncManager::removeActor(string) : invalid argument data!"; }
		
		// loop through actor list to select actor by id -nm
		for ( var i =0; i < actorList.length; i++ ){
			
			// if the current actor has the id we are looking for -nm
			if ( actorList[ i ].getId() == aId ){
			
				// remove the actor from the list -nm
				actorList.splice( i, 1 );
				
				// break the loop, actor has been removed -nm
				break;
			}
		}
		
		// sort the actor list -nm
		sort();
	}
	
	/*
	*	Get an array of strings. Each elements represents an Actor's id.
	*
	*	@Author nicholas.malacarne@gmail.com
	*
	*	@Return An array of strings.
	*/
	this.getActors	= function(){
		
		// temporary array to store each Actor id -nm
		var idList	= [];
		
		// populate our id list with each Actor id found in actor list -nm
		for ( var i = 0; i < actorList.length; i++ ){
		
			idList.push( actorList[i].getId() );
		}
		
		// return the id list -nm
		return idList;
	
	}
}